package com.example.fangwei.utilsapp.viewpager;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.fangwei.utilsapp.MainActivity;
import com.example.fangwei.utilsapp.R;
import com.fangwei.utilsLibrary.customerview.viewpager.ClipViewPager;
import com.fangwei.utilsLibrary.customerview.viewpager.RecyclingPagerAdapter;
import com.fangwei.utilsLibrary.customerview.viewpager.ScalePageTransformer;

import java.util.ArrayList;
import java.util.List;

public class ClipViewPagerActivity extends AppCompatActivity implements CustomerAdapter.OnItemClickListener {

    private ClipViewPager clipViewPager;
    private List<Integer> imgList  = new ArrayList<>();
    private CustomerAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_clip_view_pager);

        initView();
    }


    private void initView() {
        imgList.add(R.mipmap.style_jianyue);
        imgList.add(R.mipmap.style_oushi);
        imgList.add(R.mipmap.style_rishi);
        imgList.add(R.mipmap.style_jianyue);
        imgList.add(R.mipmap.style_oushi);
        imgList.add(R.mipmap.style_rishi);

        clipViewPager = ((ClipViewPager) findViewById(R.id.clipViewPager));
        clipViewPager.setPageTransformer(true,new ScalePageTransformer());

        findViewById(R.id.activity_clip_view_pager).setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return clipViewPager.dispatchTouchEvent(event);
            }
        });

        adapter = new CustomerAdapter(imgList,this);
        adapter.setOnItemClickListener(this);

        clipViewPager.setAdapter(adapter);
        clipViewPager.setOffscreenPageLimit(Math.min(imgList.size(), 5));

    }

    /**
     * 接口回调,提示哪项被点击
     * @param position 被点击的位置
     */
    @Override
    public void onItemClick(int position) {
        Toast.makeText(this, "第"+position + "项被点击了!", Toast.LENGTH_SHORT).show();
    }
}
